//
//  CalculateLoanNumericalDataViewController.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/5/4.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "CalculateLoanNumericalDataViewController.h"
#import "CalculateLoanChartsView2.h"
#import "CalculateLoanTableView.h"
#import "Masonry.h"
#import "CalculateLoanTableViewModel.h"
#import "DetailCaculateNavView.h"

@interface CalculateLoanNumericalDataViewController()<CalculateLoanTableDelegate>
@property (nonatomic, strong) CalculateLoanTableView *calculateLoanTableView;
@property (nonatomic, strong) CalculateLoanChartsView2 *calculateLoanChartsView2;
@property (nonatomic, strong) DetailCaculateNavView  *MyNavView;
@end

@implementation CalculateLoanNumericalDataViewController

#pragma mark - Life Cycle
- (void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"月还款数值详情";
    self.view.backgroundColor = [UIColor colorWithRed:0.8784 green:0.8941 blue:0.9412 alpha:1.0];
    self.view.frame = CGRectMake(0, 0, ScreenWidth*0.77, ScreenHeight);
    [self setUpConstraints];
//    [self loadDataModel];
    __weak UIViewController *weakSelf = self;
    self.MyNavView.PayBackAction = ^{
        [weakSelf.view removeFromSuperview];
        [weakSelf removeFromParentViewController];
    };
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear: animated];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = YES;
}

#pragma mark Delegate CalculateLoanTableDelegate
- (void)scrollLoanTableToIndex:(NSInteger)index{
    [self.calculateLoanChartsView2 setChartViewMoveToXPointAtIndex:index];
}

-(void)setChartsDataArray:(NSMutableArray *)dataArray andTitle:(NSString *)title{
    self.calculateLoanChartsView2.title = title;
    self.calculateLoanChartsView2.loanMoneyArray = dataArray;
}


#pragma mark - Private
- (void)setUpConstraints{
    [self.MyNavView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.width.equalTo(self.view.mas_width);
        make.height.equalTo(@(59));
    }];
    
   [self.calculateLoanChartsView2 mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.MyNavView.mas_bottom).offset(FifteenoffsetViewMargin);
       make.left.equalTo(self.view).offset(FifteenoffsetViewMargin);
       make.right.equalTo(self.view).offset(-FifteenoffsetViewMargin);
       make.height.mas_equalTo(ScreenHeight*0.4);
   }];
    [self.calculateLoanTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.calculateLoanChartsView2.mas_bottom);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-TenOffsetViewMargin);
    }];
}

- (void)loadDataModel{
    NSMutableArray *chartArray = [NSMutableArray array];
    for (int i=0; i<_loanCalculateUtil.paymentInfos.count; i++) {
        CalculateLoanTableViewModel *model = _loanCalculateUtil.paymentInfos[i];
        [chartArray addObject:model.monthlyRepayment];
    }
    self.calculateLoanChartsView2.loanMoneyArray = chartArray;
    self.calculateLoanTableView.loanTableViewArray = [NSMutableArray arrayWithArray:_loanCalculateUtil.paymentInfos];
}

#pragma mark - Getter
- (DetailCaculateNavView *)MyNavView {
    if (!_MyNavView) {
        _MyNavView = [[DetailCaculateNavView alloc] init];
        _MyNavView.isBtnShow = NO;
        _MyNavView.NavTitleString = @"房贷计算器";
        _MyNavView.BtnTitleString = @"还款详情";
        [self.view addSubview:_MyNavView];
    }
    return _MyNavView;
}

- (CalculateLoanTableView *)calculateLoanTableView{

    if (_calculateLoanTableView == nil) {
        _calculateLoanTableView = [CalculateLoanTableView new];
        _calculateLoanTableView.delegate = self;
        [self.view addSubview:_calculateLoanTableView];
    }
    return _calculateLoanTableView;
}

- (CalculateLoanChartsView2 *)calculateLoanChartsView2{

    if (_calculateLoanChartsView2 == nil) {
        _calculateLoanChartsView2 = [CalculateLoanChartsView2 new];
        [self.view addSubview:_calculateLoanChartsView2];
    }
    return _calculateLoanChartsView2;
}

@end
